/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * getFeeDialog.java
 *
 * Created on 2011-5-26, 10:48:16
 */
package junchangmis.student;

import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;
import junchangmis.*;
import publicmethod.*;
import java.sql.ResultSet;
import java.util.StringTokenizer;
import java.util.Vector;
import javax.swing.JOptionPane;

/**
 *
 * @author developers
 */
public class getFeeDialog extends javax.swing.JDialog {

    MainFrame parent;
    Vector<String> names = new Vector<String>();
    Vector<String> classCodes = new Vector<String>();

    /** Creates new form getFeeDialog */
    public getFeeDialog(java.awt.Frame parent, boolean modal, MainFrame pparent) {
        super(parent, modal);
        this.parent = pparent;
        initComponents();
        this.setTitle("催费通知——选择截止日期的时间段");
        this.setLocationRelativeTo(null);

    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jComboBoxYearStart = new javax.swing.JComboBox();
        jLabel3 = new javax.swing.JLabel();
        jComboBoxMonthStart = new javax.swing.JComboBox();
        jLabel4 = new javax.swing.JLabel();
        jComboBoxDayStart = new javax.swing.JComboBox();
        jLabel5 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jComboBoxYearEnd = new javax.swing.JComboBox();
        jLabel6 = new javax.swing.JLabel();
        jComboBoxMonthEnd = new javax.swing.JComboBox();
        jLabel7 = new javax.swing.JLabel();
        jComboBoxDayEnd = new javax.swing.JComboBox();
        jLabel8 = new javax.swing.JLabel();
        jButton1 = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);

        jLabel1.setFont(new java.awt.Font("华文细黑", 0, 24)); // NOI18N
        jLabel1.setText("起始时间：");

        jComboBoxYearStart.setFont(new java.awt.Font("华文细黑", 0, 24)); // NOI18N
        jComboBoxYearStart.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "2011", "2012", "2013", "2014", "2015", "2016", "2017", "2018", "2019", "2020" }));

        jLabel3.setFont(new java.awt.Font("华文细黑", 0, 24)); // NOI18N
        jLabel3.setText("年");

        jComboBoxMonthStart.setFont(new java.awt.Font("华文细黑", 0, 24)); // NOI18N
        jComboBoxMonthStart.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12" }));

        jLabel4.setFont(new java.awt.Font("华文细黑", 0, 24)); // NOI18N
        jLabel4.setText("月");

        jComboBoxDayStart.setFont(new java.awt.Font("华文细黑", 0, 24)); // NOI18N
        jComboBoxDayStart.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "30", "31" }));

        jLabel5.setFont(new java.awt.Font("华文细黑", 0, 24)); // NOI18N
        jLabel5.setText("日");

        jLabel2.setFont(new java.awt.Font("华文细黑", 0, 24)); // NOI18N
        jLabel2.setText("终止时间：");

        jComboBoxYearEnd.setFont(new java.awt.Font("华文细黑", 0, 24)); // NOI18N
        jComboBoxYearEnd.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "2011", "2012", "2013", "2014", "2015", "2016", "2017", "2018", "2019", "2020" }));

        jLabel6.setFont(new java.awt.Font("华文细黑", 0, 24)); // NOI18N
        jLabel6.setText("年");

        jComboBoxMonthEnd.setFont(new java.awt.Font("华文细黑", 0, 24)); // NOI18N
        jComboBoxMonthEnd.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12" }));

        jLabel7.setFont(new java.awt.Font("华文细黑", 0, 24)); // NOI18N
        jLabel7.setText("月");

        jComboBoxDayEnd.setFont(new java.awt.Font("华文细黑", 0, 24)); // NOI18N
        jComboBoxDayEnd.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "30", "31" }));

        jLabel8.setFont(new java.awt.Font("华文细黑", 0, 24)); // NOI18N
        jLabel8.setText("日");

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(45, 45, 45)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jLabel1)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jComboBoxYearStart, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabel3)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jComboBoxMonthStart, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabel4)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jComboBoxDayStart, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabel5))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jLabel2)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jComboBoxYearEnd, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabel6)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jComboBoxMonthEnd, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabel7)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jComboBoxDayEnd, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabel8)))
                .addContainerGap(43, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(26, 26, 26)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(jComboBoxYearStart, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel3)
                    .addComponent(jComboBoxMonthStart, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel4)
                    .addComponent(jComboBoxDayStart, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel5))
                .addGap(30, 30, 30)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(jComboBoxYearEnd, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel6)
                    .addComponent(jComboBoxMonthEnd, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel7)
                    .addComponent(jComboBoxDayEnd, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel8))
                .addContainerGap(19, Short.MAX_VALUE))
        );

        jButton1.setFont(new java.awt.Font("华文细黑", 0, 24)); // NOI18N
        jButton1.setText("确定");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
                    .addComponent(jButton1)
                    .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jButton1)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        try {
            // TODO add your handling code here:
            DbOperation db = new DbOperation();
            db.DbConnect();
            String sql = "select * from formalStu order by id";
            ResultSet rs = db.DBSqlQuery(sql);
            while (rs.next()) {
                //获取交费时间段长度
                int weekCount = Integer.valueOf(rs.getString("weekCount"));
                int gap = 7 * weekCount;
                //获取交费初始日期
                StringTokenizer st = new StringTokenizer(rs.getString("dateStart"), ".");
                Vector<String> temp = new Vector<String>();
                while (st.hasMoreTokens()) {
                    temp.add(st.nextToken());
                }
                int year = Integer.valueOf(temp.get(0));
                int month = Integer.valueOf(temp.get(1));
                int day = Integer.valueOf(temp.get(2));
                //获取交费终止日期
                String date = formalStuInputMethod.getEndDate(year, month, day, gap);
                //System.out.println(date);
                st = new StringTokenizer(date, ".");
                temp.clear();
                while (st.hasMoreTokens()) {
                    temp.add(st.nextToken());
                }
                int y = Integer.valueOf(temp.get(0));
                int m = Integer.valueOf(temp.get(1));
                int d = Integer.valueOf(temp.get(2));
                //获取查询的时间范围
                int yearStart = Integer.valueOf(this.jComboBoxYearStart.getSelectedItem().toString());
                int monthStart = Integer.valueOf(this.jComboBoxMonthStart.getSelectedItem().toString());
                int monthEnd = Integer.valueOf(this.jComboBoxMonthEnd.getSelectedItem().toString());
                int yearEnd = Integer.valueOf(this.jComboBoxYearEnd.getSelectedItem().toString());
                int dayStart = Integer.valueOf(this.jComboBoxDayStart.getSelectedItem().toString());
                int dayEnd = Integer.valueOf(this.jComboBoxDayEnd.getSelectedItem().toString());
                //判断交费终止日期是否在范围内
                if (yearStart <= y && y <= yearEnd) {
                    int start = (monthStart - 1) * 31 + dayStart;
                    int mid = (m - 1) * 31 + d;
                    int end = (monthEnd - 1) * 31 + dayEnd;

                    if (start <= mid && mid <= end) {
                        classCodes.add(rs.getString("classCode"));
                        names.add(rs.getString("name"));
                        //System.out.println(y + "." + m + "." + d);
                    }
                }
            }
            db.DbClose();
        } catch (SQLException ex) {
            Logger.getLogger(getFeeDialog.class.getName()).log(Level.SEVERE, null, ex);
        }
        if (names.size() > 0) {
            getFeeList fr = new getFeeList(parent, true, parent, names, classCodes);
            dispose();
            fr.setVisible(true);
        } else {
            JOptionPane.showConfirmDialog(null, "没有记录！", "提示", JOptionPane.CLOSED_OPTION, JOptionPane.WARNING_MESSAGE);
        }
    }//GEN-LAST:event_jButton1ActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /*   java.awt.EventQueue.invokeLater(new Runnable() {
        public void run() {
        getFeeDialog dialog = new getFeeDialog(new javax.swing.JFrame(), true);
        dialog.addWindowListener(new java.awt.event.WindowAdapter() {
        public void windowClosing(java.awt.event.WindowEvent e) {
        System.exit(0);
        }
        });
        dialog.setVisible(true);
        }
        });*/
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButton1;
    private javax.swing.JComboBox jComboBoxDayEnd;
    private javax.swing.JComboBox jComboBoxDayStart;
    private javax.swing.JComboBox jComboBoxMonthEnd;
    private javax.swing.JComboBox jComboBoxMonthStart;
    private javax.swing.JComboBox jComboBoxYearEnd;
    private javax.swing.JComboBox jComboBoxYearStart;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JPanel jPanel1;
    // End of variables declaration//GEN-END:variables
}
